/* ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   Module Name          : com.yaodian100.core.logger.service.impl.YDSMTPAppender
   Module Description   :

   Date Created      : 2010/8/11
   Original Author   : jeffma
   Team              : yaodian100
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   MODIFICATION HISTORY
   ------------------------------------------------------------------------------
   Date Modified       Modified by       Comments
   ------------------------------------------------------------------------------
   ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/
package com.yaodian100.core.logger.service.impl;

import java.net.InetAddress;
import java.net.UnknownHostException;

import org.apache.log4j.net.SMTPAppender;
import org.apache.log4j.spi.TriggeringEventEvaluator;

import com.yaodian100.core.common.utils.DateUtil;

/**
 * @author jeffma
 *
 */
public class YDSMTPAppender extends SMTPAppender {

	private InetAddress thisIp = null;

	/** default constructor */
	public YDSMTPAppender() {
		try {
			thisIp = InetAddress.getLocalHost();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
	}

	/** default constructor */
	public YDSMTPAppender(TriggeringEventEvaluator evaluator) {
		super(evaluator);
		try {
			thisIp = InetAddress.getLocalHost();
		} catch (UnknownHostException e) {
			e.printStackTrace();
		}
	}

	/*
	 * (non-Javadoc)
	 * @see org.apache.log4j.net.SMTPAppender#sendBuffer()
	 */
	@Override
	protected void sendBuffer() {
		try {
			if (getSubject() != null && thisIp != null) {
				msg.setSubject(getSubject() + " - " + thisIp.getHostName() + " - "
						+ DateUtil.convertDateToString("yyyy-MM-dd", DateUtil.getCurrentTime()));
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		super.sendBuffer();
	}
}
